//
//  NSMutableArray+Shuffle.m
//  meets-ios
//
//  Created by Mark on 15/5/15.
//  Copyright (c) 2015年 meets. All rights reserved.
//

#import "NSMutableArray+Shuffle.h"

@implementation NSMutableArray (Shuffle)

- (void)shuffle {
    NSMutableArray *randomArray = [NSMutableArray new];
    NSUInteger originalCount = [self count];
    
    for (NSUInteger i = 0; i < originalCount; i++) {
        NSUInteger index = arc4random() % [self count];
        [randomArray addObject:[self objectAtIndex:index]];
        [self removeObjectAtIndex:index];
    }
    
    [self addObjectsFromArray:randomArray];
}

@end
